<?php

namespace app\api\controller;

use think\Db;

class Index extends Base
{
    public function index()
    {
        return self::errors('数据有误');
        $data = [
            [
                'name' => 'zhangsan',
                'age => 18'
            ],
            [
                'name' => 'zhangsan',
                'age => 18'
            ],
            [
                'name' => 'zhangsan',
                'age => 18'
            ]
        ];
        return self::successs($data);
    }

    public function index2()
    {
        //return self::errors('数据有误');
        $data = [
            [
                'name' => 'zhangsan2',
                'age => 18'
            ],
            [
                'name' => 'zhangsan2',
                'age => 18'
            ],
            [
                'name' => 'zhangsan2',
                'age => 18'
            ]
        ];
        return self::successs($data);
    }

    public function test()
    {
        sleep(1);
        //return self::errors('加载数据有误');
        $datas = Db::name('admin_log')->paginate($this->size);
        return self::successs($datas);
    }

    private function buildDatas($length = 10)
    {
        $datas = [];
        for ($i = 0; $i < $length; $i++) {
            $datas[] = [
                'name' => 'zhangsan',
                'age' => 18
            ];
        }

        return $datas;
    }


    /**
     * 获取系统配置
     *
     * @return void
     */
    public function getSystemConfig()
    {
        $key = input('key/s', '');
        if (empty($key)) {
            $key = [
                'app_name', 'company', 'tel'
            ];
        }
        $data = get_system_config($key);
        return self::successs(is_array($data) ?  $data : [$key => $data]);
    }
}
